package com.example.demo.domain.security;

import javax.persistence.AttributeConverter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class StringListConverter implements AttributeConverter<List<String>,String> {


    @Override
    public String convertToDatabaseColumn(List<String> strings) {
        return String.join(",",strings);
    }

    //将字符串转化为实体的属性
    @Override
    public List<String> convertToEntityAttribute(String s) {
        if ("".equals(s)) {
            return new ArrayList<>();
        }
        return new ArrayList<>(Arrays.asList(s.split(",")));
    }
}
